#!/usr/bin/env python3
"""
PaddleOCR API Service 启动脚本

快速启动OCR API服务的便捷脚本
"""

import sys
import os

def main():
    """主函数"""
    print("🚀 启动PaddleOCR API Service...")
    print("=" * 50)
    
    # 检查依赖
    try:
        import flask
        import paddleocr
        import requests
        import PIL
        print("✅ 依赖检查通过")
    except ImportError as e:
        print(f"❌ 缺少依赖: {e}")
        print("请运行: pip install -r requirements.txt")
        sys.exit(1)
    
    # 启动应用
    try:
        from app import app, init_global_resources, init_ocr_on_startup, start_worker_thread

        print("🔄 初始化全局资源...")
        init_global_resources()

        print("🔄 初始化OCR模型...")
        init_ocr_on_startup()

        print("🔄 启动工作线程...")
        start_worker_thread()
        
        print("=" * 50)
        print("🌐 服务地址:")
        print("   主页: http://localhost:5000")
        print("   📚 Swagger文档: http://localhost:5000/docs/")
        print("   📋 API信息: http://localhost:5000/api/v1/info")
        print("   🔍 健康检查: http://localhost:5000/api/v1/health")
        print("=" * 50)
        print("按 Ctrl+C 停止服务")
        print("=" * 50)
        
        app.run(host='0.0.0.0', port=5000, debug=False, threaded=True)
        
    except KeyboardInterrupt:
        print("\n👋 服务已停止")
    except Exception as e:
        print(f"❌ 启动失败: {e}")
        sys.exit(1)

if __name__ == '__main__':
    main()
